﻿using MiniErp.Entity.DataStreams;
using MiniErp.Entity.DataStreams.DOs;
using MiniErp.Entity.DataStreams.DOs.AssetManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniErp.Mysql.Data
{
    public class DbInitializer
    {
        /// <summary>
        /// 数据库初始化类(必须先生成从表) 并且，实体有做字段的增加或者删减，本类配置项对应也要做出增加或者删减
        /// </summary>
        /// <param name="_context"></param>
        public void Initialize(MysqlContext _context)
        {
            _context.Database.EnsureCreated();

            if (!_context.rights.Any())
            {
                var rights = new List<Rights>
            {
            new Rights{ RightsId=1,RightName="God",RightDescribe="最高级权限"},
            new Rights{ RightsId=2,RightName="Admin",RightDescribe="管理员权限"},
            new Rights{ RightsId=3,RightName="Root",RightDescribe="用户权限"},
            new Rights{ RightsId=4,RightName="Tourist",RightDescribe="游客权限"},
            };
                rights.ForEach(item =>
                {
                    _context.rights.Add(item);
                });
                _context.SaveChanges();
            }
            if (!_context.titles.Any())
            {
                var titles = new List<Titles>
                {
                    new Titles{TitlesId=1,TitlesName="资深经理",TitlesDescribe="管理整个较为重要的部门"},
                    new Titles{TitlesId=2,TitlesName="经理",TitlesDescribe="管理整个部门"},
                    new Titles{TitlesId=3,TitlesName="副经理",TitlesDescribe="协助经理管理整个部门"},
                    new Titles{TitlesId=4,TitlesName="课长",TitlesDescribe="管理整个课"},
                    new Titles{TitlesId=5,TitlesName="副课长",TitlesDescribe="协助课长管理整个课"},
                    new Titles{TitlesId=6,TitlesName="资深工程师",TitlesDescribe="设计项目"},
                    new Titles{TitlesId=7,TitlesName="工程师",TitlesDescribe="带领助理工程师做项目"},
                    new Titles{TitlesId=8,TitlesName="副工程师",TitlesDescribe="带领助理工程师做项目"},
                    new Titles{TitlesId=9,TitlesName="助理工程师", TitlesDescribe="跟随工程师or副工程师做项目"},
                    new Titles{TitlesId=10,TitlesName="生产技术员",TitlesDescribe="主要生产人员"}
                };
                titles.ForEach(item =>
                {
                    _context.titles.Add(item);
                });
                _context.SaveChanges();
            }
            if (!_context.departments.Any())
            {
                var departments = new List<Department>
            {
            new Department{DepartmentId=1,DepartmentName="工程部"},
            new Department{DepartmentId=2,DepartmentName="咨询部"}
            };
                departments.ForEach(item =>
                {
                    _context.departments.Add(item);
                });
                _context.SaveChanges();
            }

            if (!_context.userInfos.Any())
            {
                var userInfos = new List<UserInfo>
            {
            new UserInfo{UId=210001,PassWord="123456",UserName="张三",State=true,PhoneNumber=12345678901,MailBox="",RightsId=1,DepartmentId=1,TitlesId=9},
            new UserInfo{UId=210002,PassWord="123456",UserName="李四",State=true,PhoneNumber=12345678901,MailBox="",RightsId=2,DepartmentId=1,TitlesId=9},
            new UserInfo{UId=210003,PassWord="123456",UserName="王五",State=true,PhoneNumber=12345678901,MailBox="",RightsId=3,DepartmentId=1,TitlesId=9},
            new UserInfo{UId=210004,PassWord="123456",UserName="赵六",State=true,PhoneNumber=12345678901,MailBox="",RightsId=4,DepartmentId=1,TitlesId=9},
            };
                userInfos.ForEach(item =>
                            {
                                _context.userInfos.Add(item);
                            });
                _context.SaveChanges();
            }



            if (!_context.generalTypes.Any())
            {
                var generalType = new List<GeneralType>
            {
            new GeneralType{GeneralTypeId=1001,GeneralTypeName="生产用品"},
            new GeneralType{GeneralTypeId=1002,GeneralTypeName="办公用品"},
            new GeneralType{GeneralTypeId=1003,GeneralTypeName="基建用品"},
            };
                generalType.ForEach(item =>
                {
                    _context.generalTypes.Add(item);
                });
                _context.SaveChanges();
            }

            if (!_context.secondaryTypes.Any())
            {
                var secondaryType = new List<SecondaryType>
            {
            new SecondaryType{SecondaryTypeId=1001,SecondaryTypeName="产测电脑"},
            new SecondaryType{SecondaryTypeId=1002,SecondaryTypeName="办公电脑"}
            };
                secondaryType.ForEach(item =>
                {
                    _context.secondaryTypes.Add(item);
                });
                _context.SaveChanges();
            }

            if (!_context.assetStates.Any())
            {
                var assetStates = new List<AssetState>
            {
            new AssetState{AssetStateId=1,AssetStateName="空闲"},
            new AssetState{AssetStateId=2,AssetStateName="外借"},
            new AssetState{AssetStateId=3,AssetStateName="维修"}
            };
                assetStates.ForEach(item =>
                {
                    _context.assetStates.Add(item);
                });
                _context.SaveChanges();
            }



            if (!_context.positions.Any())
            {
                var positions = new List<Position>
            {
            new Position{PositionId=1,PositionName="工程部办公室",PositionAddress="A栋一楼右侧"},
            new Position{PositionId=2,PositionName="TE办公室",PositionAddress="工程部大办公室旁，A栋一楼右侧"},
            new Position{PositionId=3,PositionName="TE仓库",PositionAddress="B栋一楼右侧"},
            new Position{PositionId=4,PositionName="咨询部",PositionAddress="A栋一楼左侧"},
            };
                positions.ForEach(item =>
                {
                    _context.positions.Add(item);
                });
                _context.SaveChanges();
            }


            if (!_context.assetInfos.Any())
            {
                var assetInfos = new List<AssetInfo>
            {
            new AssetInfo{AllId="10011001100001",AId=100001,GeneralTypeId=1001,SecondaryTypeId=1001,DepartmentId=1,UserInfoId=210001,AssetStateId=1,AssetName="Win10测试电脑",PositionId=3},
            new AssetInfo{AllId="10021002100001",AId=100001,GeneralTypeId=1002,SecondaryTypeId=1002,DepartmentId=1,UserInfoId=210001,AssetStateId=1,AssetName="Win10测试电脑",PositionId=3},
            new AssetInfo{AllId="10011001100001",AId=100002,GeneralTypeId=1001,SecondaryTypeId=1001,DepartmentId=1,UserInfoId=210003,AssetStateId=2,AssetName="Win10测试电脑",PositionId=2},
            new AssetInfo{AllId="10011002100001",AId=100001,GeneralTypeId=1001,SecondaryTypeId=1002,DepartmentId=1,UserInfoId=210001,AssetStateId=1,AssetName="Win10测试电脑",PositionId=4},
            new AssetInfo{AllId="10021001100001",AId=100001,GeneralTypeId=1002,SecondaryTypeId=1001,DepartmentId=2,UserInfoId=210002,AssetStateId=3,AssetName="Win10测试电脑",PositionId=3},
            new AssetInfo{AllId="10011001100001",AId=100003,GeneralTypeId=1001,SecondaryTypeId=1001,DepartmentId=1,UserInfoId=210001,AssetStateId=1,AssetName="Win10测试电脑",PositionId=3}
            };
                assetInfos.ForEach(item =>
                {
                    _context.assetInfos.Add(item);
                });
                _context.SaveChanges();
            }

            if (!_context.assetModificationTypes.Any())
            {
                var assetModificationTypes = new List<AssetModificationType>
                {
                    new AssetModificationType{AMTId=1,AMTName="新增",Remarks="新增资产"},
                    new AssetModificationType{AMTId=2,AMTName="删除",Remarks="删除资产"},
                    new AssetModificationType{AMTId=3,AMTName="借出",Remarks="借出资产"},
                    new AssetModificationType{AMTId=4,AMTName="归还",Remarks="归还资产"},
                    new AssetModificationType{AMTId=5,AMTName="转移",Remarks="转移资产"},
                    new AssetModificationType{AMTId=6,AMTName="维修",Remarks="维修资产"},
                };
                assetModificationTypes.ForEach(item =>
                {
                    _context.assetModificationTypes.Add(item);
                });
                _context.SaveChanges();
            }



        }


    }
}
